package org.alanlau.alibaba.feign;

import feign.hystrix.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * @author liukun
 * @version 1.0
 * @date 2020/11/27 16:36
 */
@FeignClient(value = "cloud-alibaba-demo", fallbackFactory = TestFallback.class)
public interface TestClient {
    @GetMapping("/hello")
    String sayHello();

    @GetMapping("/hello2")
    String sayHello2();
}

@Component
class TestFallback implements FallbackFactory<TestClient> {

    @Override
    public TestClient create(Throwable throwable) {
        return new TestClient() {
            @Override
            public String sayHello() {
                return "hello回退了";
            }

            @Override
            public String sayHello2() {
                return "hello2回退了";
            }
        };
    }
}
